<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title>添加班级</title>
    <link rel="stylesheet" href="/static/css/pintuer.css">
    <link rel="stylesheet" href="/static/css/admin.css">
    <script src="/static/js/jquery.js"></script>
    <script src="/static/js/pintuer.js"></script>
    <!--    <base href="${pageContext.request.contextPath}/">-->

</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head"><strong><span class="icon-pencil-square-o"></span>修改班级信息</strong></div>
    <div class="body-content">
        <form class="form-clazz" action="">
            <div class="form-group">
                <div class="label">
                    <input type="text" name="cid" id="cid" value="" hidden/>
                    <label>班级名称：</label>
                </div>
                <div class="field">
                    <input type="text" class="input" name="cname" id="cname" value="" style="width:30%"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>班主任：</label>
                </div>
                <div class="field">
                    <input type="text" class="input" name="cteacher" id="cteacher" value="" style="width:30%"/>
                </div>
            </div>

            <div class="form-group">
                <div class="label">
                    <label>备注：</label>
                </div>
                <div class="field">
                    <textarea type="text" class="input" name="remark" id="remark" style="height:80px;"></textarea>
                </div>
            </div>

            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button id="btn" class="button bg-main icon-check-square-o" type="button"> 提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    $(function () {
        //发送异步 获取id
        let uri = location.search;
        uri = uri.substring(1);
        //console.log(uri);
        let data = uri.split("=");
        let cid = data[1];
        console.log('----', cid);
        $("#cid").val(cid);
        onload(cid)
    })

    function onload(cid) {
        $.ajax({
            url: "/clazz/updatePage",
            data: "cid=" + cid,
            type: "get",
            dataType: "json",
            success: function (res) {
                $("#cname").val(res.data.cname);
                $("#cteacher").val(res.data.cteacher);
                $("#remark").val(res.data.remark);
            }
        })
    }

    $('#btn').click(function () {
        //console.log("click")
        $.ajax({
            url: "UpdateClassServlet",
            data: $(".form-clazz").serialize(),
            type: "get",
            dataType: "json",
            success: function (res) {
                if (res.code = 0) {
                    alert("修改失败");
                } else {
                    alert("修改成功");
                    location.href="listClazz.html";
                }
            }
        })
    });

</script>
</html>
